// state
const initState = {
  token: "",
  phone: "电话号码",
};

// action creator
export const setPhone = (payload) => {
  return {
    type: "SET_PHONE",
    payload,
  };
};

export const setToken = (payload) => {
  return {
    type: "SET_TOKEN",
    payload,
  };
};

// reduces
export default (state = initState, action) => {
  let { type, payload } = action;
  // 根据action的type， 执行不能的操作
  switch (type) {
    case "SET_PHONE":
      return {
        // reducer是纯函数， 不能改变参数state， 在这里把state全拿过来
        ...state,
        phone: payload,
      };
    case "SET_TOKEN":
      return {
        ...state,
        token: payload,
      };
    default:
      return state;
  }
};
